const App = getApp();
import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    markers:[],
    polyline:[],
    info:{},
    lng:"",
    lat:"",
    nowaddress:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that =this;
    var orderid = options.orderid;
    console.log("orderid",orderid);
    // orderid=22;


    App._post_form('wxapi/order/info', {
      id:orderid
    }, function(result) {
      
        if(result.status=="200"){
        
          that.setData({info:result.data})
           that.getaddress(result.data.carnumber)
        }
    });

   
   

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  goinfo:function(e){
    var id =  this.data.info.id;
    wx.navigateTo({
      url: '/pages/order/qr?orderid='+id,
    })
  },
  getaddress(carnumber){
    var that =this;

    
    App._post_form('wxapi/address', {
      carnumber:carnumber
    }, function(mydata) {
        console.log("mydata",mydata)
      
        if(mydata.status=="200"){
        
            that.setData({
              lat: mydata.data.lat,
              lng:mydata.data.lng,
              nowaddress:mydata.data.address,
              markers:[{
                latitude: mydata.data.lat,
                longitude: mydata.data.lng
              }]
            })
        }
    },function(fail){

      console.log("出错了",fail);
    });
   
  },
  quxiao:function(e){
    console.log("sssssss");
    var id =  this.data.info.id;
    var token = wx.getStorageSync('token');
    var that = this;
    Dialog.confirm({
      title: '取消预约记录',
      message: '您正在取消乘车预约记录，当天您还有2次取消预约的机会，确定取消吗？',
    })
      .then(() => {
        App._post_form('wxapi/order/del', {
          token:token,id:id
        }, function(result) {
          
            if(result.status=="200"){
               
              wx.showToast({
                title: '操作成功',
                icon: 'succes',
                duration: 1000,
                mask:true
            })
             setTimeout(() => {
              wx.navigateBack({
                delta: 1
              })
             }, 1000);
                
            }else{
              App.showError(result.message, () => {
               
              });
            }
        });
        
        // on confirm
      })
      .catch(() => {
        // on cancel
      });
  }
})